package org.dinner.order.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@NamedQueries({
	@NamedQuery(name="Order.list", query="from Order"),
	@NamedQuery(name="Order.getByShippmentDate", query="from Order o where o.unit.id=:suId and o.shipmentDate=:date"),
	@NamedQuery(name="Order.getByMenuId", query="from Order o where o.unit.id=:suId and o.menu.id=:menuId")
})

@Table(name = "ORDERS")
public class Order {
	
	@Id
	@GeneratedValue
	private int id;
	private Date date;
	@Column(unique = true)
	private Date shipmentDate;
	@ManyToMany
	@JoinTable(name = "ORDERED_ITEMS")
	private List<OrderItem> items = new ArrayList<OrderItem>();
	@ManyToOne
	@JoinColumn(name = "unit_id")
	private ShippingUnit unit;
	@ManyToOne
	@JoinColumn(name = "menu_id")
	private Menu menu;
	private boolean active;
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public Date getShipmentDate() {
		return shipmentDate;
	}
	public void setShipmentDate(Date shipmentDate) {
		this.shipmentDate = shipmentDate;
	}
	public List<OrderItem> getItems() {
		return items;
	}
	public void setItems(List<OrderItem> items) {
		this.items = items;
	}
	public ShippingUnit getUnit() {
		return unit;
	}
	public void setUnit(ShippingUnit unit) {
		this.unit = unit;
	}
	public Menu getMenu() {
		return menu;
	}
	public void setMenu(Menu menu) {
		this.menu = menu;
	}
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	
	

}
